function LocationAction(days, location) {
    this._days = days;
    this._location = location;
}

LocationAction.prototype = {
    apply: function(repository, recordHistoryCallback) {
        var monthsOfDaysToSave = this._getMonthsToSave();

        var travelStepsToRemove = this._getTravelStepsToRemove();

        var monthsOfTravelStepsToSave = [];
        if(travelStepsToRemove.length > 0){
            monthsOfTravelStepsToSave = repository.getApplicableMonths(TravelStep.getDateRange(travelStepsToRemove));
        }
        
        var monthsToSave = monthsOfDaysToSave.concat(monthsOfTravelStepsToSave).unique();
        recordHistoryCallback(monthsToSave, { add: travelStepsToRemove});
        repository.saveTravelSteps({remove: travelStepsToRemove});

        this._setLocation();

        repository.markAsChanged(monthsToSave);
        
    },
    applyUI: function(calendarViewBody) {
        calendarViewBody.updateLocations();
    },
    _setLocation: function() {
        var me = this;
        this._days.foreach(function(day) {
            day.setLocation(me._location);
        });
    },
    
    _getMonthsToSave: function() {
        var months = [];
        this._days.foreach(function(day) {
            months.push(day.parentMonth());
        });
        return months.unique();
    },

    _getTravelStepsToRemove: function(){
        var travelSteps = [];
        this._days.foreach(function(day) {
            travelSteps = travelSteps.concat(day.getTravelSteps());
        });
        return travelSteps.unique();
    }

};
